package com.student.liu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.student.liu.entity.Asset;
import com.student.liu.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.Map;

public interface IAssetMapper extends BaseMapper<Asset> {

    /**
     * 根据部门名称查询数量
     * @param name
     * @return
     */
    @Select("select count(0) from asset where name=#{asset}")
    int selectCountByName(String name);

    @Select("select asset.id as 'id', asset_no, asset,department.name as 'departmentname', nav,number,registertime from asset " +
            "inner join department on asset.department_id=department.id " +
            "${ew.customSqlSegment}")
    IPage<Map<String, Object>> selectAssetJoinDetAndRolPage(Page page, @Param("ew") Wrapper queryWrapper);


    /**
     * 新增部门
     * @param asset
     * @return
     */
    @Insert("insert into asset values(default,#{assetNo},#{asset},#{departmentId},#{nav},#{number},#{registertime}")
    @Options(
            keyProperty = "id",
            useGeneratedKeys = true
    )
    int insertAsset(Asset asset);

    /**
     * 修改部门
     * @param asset
     * @return
     */
    @Update("update asset set asset=#{asset},asset_no=#{assetNo},department_id=#{departmentId},nav=#{nav},number=#{number} where id=#{id};")
    int update(Asset asset);

    /**
     * 删除部门
     * @param id
     * @return
     */
    @Delete("delete from asset where id=#{id}")
    int delete(Integer id);
    
}
